package com.laconic.vbenadmin.controller;

import com.laconic.vbenadmin.SingleResponse;
import com.laconic.vbenadmin.bean.LoginResp;
import com.laconic.vbenadmin.bean.UserInfo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author JiangLiu
 * @Date 2025/5/23 00:17
 **/
@CrossOrigin
@RestController
@RequestMapping("/api")
public class UserController {


    @PostMapping("/auth/login")
    public SingleResponse login(@RequestBody Map<String, String> loginMap, HttpServletRequest servletRequest) {

        for (Map.Entry<String, String> entry : loginMap.entrySet()) {
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }
        LoginResp loginResp = new LoginResp();
        loginResp.setAccessToken("accessToken123test");
        return SingleResponse.success(loginResp);
    }


    @GetMapping("/user/info")
    public SingleResponse<UserInfo> getUserInfo(HttpServletRequest servletRequest) {
        UserInfo info = new UserInfo();
        info.setUserId("1");
        info.setUsername("管username");
        info.setRealName("管管");
        info.setAvatar("https://example.com/avatar.png");
        String[] roles = new String[]{"admin", "002"};
        info.setRoles(roles);
        info.setDesc("系统管理员");
        info.setToken("已通过登录接口下发，无需重复返回");
        return SingleResponse.success(info);
    }

    @GetMapping("/auth/codes")
    public SingleResponse getAccessCodes(HttpServletRequest servletRequest) {
        System.out.println(servletRequest);
        String[] ans = new String[0];
        return SingleResponse.success(ans);
    }
}
